<template>
  <div class="app-container">
    <el-table
      element-loading-text="Loading"
      :data="departmentList"
      border
      fit
      style="width: 100%"
      highlight-current-row
    >
      <el-table-column label="部门名称" align="center">
        <template slot-scope="scope">{{ scope.row.depName }}</template>
      </el-table-column>
<!--      <el-table-column label="授权类型" align="center">-->
<!--        <template slot-scope="scope">{{ scope.row.allType }}</template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="small" @click="choosePer(scope.row.depCode)">查看权限</el-button>
        </template>
      </el-table-column>

    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      align="center"
    ></el-pagination>
  </div>
</template>

<script>
  import $ from "@/api/permissSet"

  export default {
    data() {
      return {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        departmentList: [],
      }
    },
    created() {
      // 部门列表
      this.fetchData()
    },
    methods: {
      choosePer(id) {
        this.$router.push({
          path: "choose",
          query:{id:id}
        });
      },

      fetchData() {
        this.currentPage = 1
        $.tbDmList({
          pageIndex: this.currentPage,
          pageSize: this.pageSize
        }).then(res => {
          this.departmentList = res.data.list
          this.total = res.data.total;
          for (let argument of this.departmentList) {
            let aa=[]
            if (argument.tbAuthDmList==null) argument.tbAuthDmList=[]
            for (let re of argument.tbAuthDmList) {
              aa.push(re.type_name)
            }
            this.$set(argument, "allType", aa+"");
          }
          // console.log(this.departmentList)
        })
      },

      // 翻页查看
      find(pageIndex) {
        $.tbDmList({
          pageIndex: pageIndex,
          pageSize: this.pageSize
        }).then(res => {
          this.departmentList = res.data.list
          this.total = res.data.total;
          // for (var i = 0; i < this.administratorList.length; i++) {
          //   this.$set(this.administratorList[i], "a", i + 1);
          // }

        })
      },

      handleSizeChange(val) {
        this.pageSize = val;
        this.currentPage = 1;
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },

      handleCurrentChange(val) {
        this.currentPage = val;
        //console.log(val)
        if (this.state == 1) {
          this.find(this.currentPage)
        } else this.find(this.currentPage)
      },
    }
  }
</script>
